//拼团列表
exports.bulk_purchase_before_pay = function (req, res) {

    //获取restful参数
    var bodyParams = req.routeInfo.bodyParams;

    //最终结果
    var resultData = {};
    var lock = 0;
    var o_id = 0;
    //任务流创建
    async.waterfall([

            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.search_bulk_purchase_lock + "/bpl_fid/" + bodyParams.f_id + "/bpl_oaid/"+bodyParams.oa_id +"/bpl_uid/" + bodyParams.order_NO,
                        method: 'POST',
                        data: {
                            fields: ["bpl_id","create_time"].join(",")
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }

                      lock = data.data;
                        cb();
                    }
                );

            },
            //查询订单id
            function(cb){
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.search_order + "/o_no/" + bodyParams.order_NO,
                        method: 'POST',
                        data: {
                            fields: ["o_id"].join(",")
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }

                        o_id = data.data;

                        cb();
                    }
                );
            },


           function (cb){
                if(parseInt(lock[0].create_time) + 20 > common.nowTime(false)){
                    resultData.can_pay = 1;
                    cb()
                }else{

                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.update_order ,
                            method: 'POST',
                            data: {
                                o_id : o_id[0].o_id,
                                o_pay_status : 4,
                            }
                        },
                        function (err, data) {
                            //判断是否有错误信息
                            if (err) {
                                return cb(err, data);
                            }

                            resultData.can_pay = 0;
                            cb();
                        }
                    );


                }
             },


        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

}